package presentation;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import domain.EmpresaPrivada;
import domain.LineaPresupuesto;

/**
 * Servlet implementation class for Servlet: InsertarLinea
 * 
 */
public class InsertarLinea extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public InsertarLinea() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	public void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession sesion = request.getSession();
		LineaPresupuesto lin = new LineaPresupuesto();
		lin.setPrId(Integer.parseInt(request.getParameter("idpresupuesto")));
		lin.setDescripcion(request.getParameter("descripcion"));
		lin.setHerramientas(request.getParameter("herramientas"));
		lin.setReHumanos(request.getParameter("recursos"));
		lin.setTiempo(Integer.parseInt(request.getParameter("tiempo")));
		lin.setPrecio(Integer.parseInt(request.getParameter("precio")));
		lin.setTId(Integer.parseInt(request.getParameter("idtarea")));
		lin.setNombre(request.getParameter("nombre"));
		lin.setMateriales(request.getParameter("materiales"));
		EmpresaPrivada EP = new EmpresaPrivada();
		String resource = "./error/error.jsp";
		if (EP.insertarLinea(lin)) {
			resource = "./EmpresaPrivada/entrada.jsp";
			RequestDispatcher d = request.getRequestDispatcher(resource);
			if (d != null) {
				d.forward(request, response);
			}
		} else {
			response.sendRedirect(resource);
		}

	}

		
		

	}

